Fix issue #280: Add support for persistent callbacks#282
Merged
happydog-intj merged 1 commit intomasterfrom Jun 13, 2025
Merged
Fix issue #280: Add support for persistent callbacks#282happydog-intj merged 1 commit intomasterfrom
happydog-intj merged 1 commit intomasterfrom
Conversation
- Add persistent callback functionality to prevent callbacks from being deleted after first use - Implement callHandlerPersistent() method for Java side - Implement callHandlerPersistent() method for JavaScript side - Add registerPersistentCallback() and removePersistentCallback() methods - Update BaseJavascriptInterface to support persistent callbacks - Add comprehensive tests for persistent callback functionality - Add demo HTML page showing persistent callback usage - Update README with documentation for new persistent callback feature This allows callbacks to be cached and reused multiple times, fixing the issue where Android side couldn't reuse cached callbacks from JavaScript handlers.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #280 by adding support for persistent callbacks that can be reused multiple times without being deleted after first use.
Problem
The original issue reported that when caching a callback function from a JavaScript handler and trying to reuse it multiple times from the Android side, it doesn't work correctly after the first use. This was because callbacks were being deleted from the
responseCallbacksobject after first use, preventing reuse.Solution
JavaScript Side Changes
persistentCallbacksobject to track callbacks that should not be deletedcallHandlerPersistent()method for creating persistent callbacksregisterPersistentCallback()andremovePersistentCallback()methods for manual management_doSend()and_dispatchMessageFromNative()to check if a callback is persistent before deleting itJava Side Changes
mPersistentCallbacksmap to track persistent callbackscallHandlerPersistent()method for creating persistent callbacksdoSendPersistent()method for internal handlingBaseJavascriptInterface.response()to not delete persistent callbacksAdditional Improvements
Usage Examples
Java Side
JavaScript Side
Testing
Backward Compatibility
This change is fully backward compatible. All existing code will continue to work exactly as before. The new persistent callback functionality is opt-in through new methods.
Fixes #280
@uknownothingsnow can click here to continue refining the PR